﻿using System.Data.SqlTypes;
using System.Text.RegularExpressions;

public class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString RegexReplace(SqlString aText, SqlString aPattern, SqlString aReplacePattern)
    {
        return new SqlString(Regex.Replace(aText.ToString(), aPattern.ToString(), aReplacePattern.ToString()));
    }

    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString RegexGetMatch(SqlString aText, SqlString aPattern)
    {
        return new SqlString(Regex.Match(aText.ToString(), aPattern.ToString()).Value);
    }
}
